﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;

public class ConfigFlyitemContent : MonoBehaviour
{
    public Image m_FlyingItemImage;
    public InputField m_FlyItemNameEdit;
    public Weapon m_Weapon;
    public FlyItem m_FlyItem;
    public List<FlyItemParameter> m_Parameters = new List<FlyItemParameter>();

    void Start()
    {
        var height = m_FlyingItemImage.GetComponent<RectTransform>().rect.height;
        var size = m_FlyingItemImage.GetComponent<RectTransform>().sizeDelta;
        m_FlyingItemImage.GetComponent<RectTransform>().sizeDelta = new Vector2((int)height / 2, size.y);
    }
    public void ApplyData()
    {
    }
    public void Load(Weapon weapon)
    {
        m_Weapon = weapon;
    }
    public void Init(FlyingItemUI item)
     { 
        m_FlyingItemImage.sprite = item.m_Sprite;
        m_FlyItem = item.m_FlyItem;

        
        foreach(var i in m_Parameters)
        {
            i.gameObject.SetActive(false);
            if (i.m_WeaponType == m_Weapon.m_Type)
            {
                i.gameObject.SetActive(true);
                i.Init(m_FlyItem);
            }
        }

        m_FlyItemNameEdit.text = m_FlyItem.name;
    }
    public void OnNameEditfinished(string value)
    {
        m_FlyItem.name = value;
    }
}